import math

import numpy as np

class BaseAttack:
    def __init__(self, name, model, config, batch_size, targeted, llc):
        self.name = name
        self.model = model
        self.config = config
        self.batch_size = batch_size
        self.targeted = targeted
        self.llc = llc

    def attack_batch(self, images, labels):
        print('Method `attack_batch` must be implemented')
        raise NotImplementedError

    def attack(self, images, labels):
        adv_images = []

        batch_count = int(math.ceil(len(images) / self.batch_size))
        for ind in range(batch_count):
            start = ind * self.batch_size
            end = min((ind + 1) * self.batch_size, len(images))
            print('\rGenerating {} ~ {}'.format(start, end), end = ' ')
            batch_adv_images = self.attack_batch(images[start:end], labels[start:end])
            adv_images.extend(batch_adv_images)
        print()
        return np.array(adv_images)
